package tr.com.netgis.web;

import java.util.List;

import tr.com.netgis.NGApplication;
import tr.com.netgis.db.NGDbHelper;
import tr.com.netgis.pojo.Message.Command;
import android.database.sqlite.SQLiteDatabase;

/**
 * 
 * @author NetGis
 *
 */
public class RequestHandler implements IRequestHandler {

	protected NGDbHelper mHelper;
	protected SQLiteDatabase mDb;
	
	public RequestHandler() {
		super();
		initializeDB();
	}

	private void initializeDB (){
		mHelper = new NGDbHelper(NGApplication.getAppContext());	
		mDb = mHelper.getWritableDatabase();		
	}
	
	public void call(SetLocationResponse response) {
		if (response.isSuccessful()) {
			/*
			Looper.prepare();
			new CallTask().execute(response);
			Looper.loop();
			*/
			mHelper.insertMessage(response.getMessages());
			List<Command> commands = response.getCommands();
			
		}
		
		try {
			mHelper.close();
			mDb.close();			
		} catch (Exception e) {
		}
	}

	/*
	private class CallTask extends AsyncTask<SetLocationResponse, Void, String> {
		@Override
		protected String doInBackground(SetLocationResponse... responses) {
			List<Message> messages = new ArrayList<Message>();
			for (SetLocationResponse response : responses) {
				messages.addAll(response.getMessages());
			}
			mHelper.insertMessage(messages);
			return messages.size() + " tane mesaj kaydedildi.";
		}

		@Override
		protected void onPostExecute(String result) {
			Log.i ("RequetHandler", result);
			try {
				mHelper.close();
				mDb.close();			
			} catch (Exception e) {
			}
		}
	}
	*/
	
}
